<?php
namespace Home\Controller;
use Home\Controller\HomeController;
class GroupController extends HomeController {
    public function index(){
        $this->assign('title','每日团购');
        $this->show('<link rel="stylesheet" href="__PUBLIC__/Home/css/group.css" type="text/css"/>
');
        $Model = new \Think\Model();
        $list = $Model->field(array('g.id as gid,s.id as sid ,s.begin_time,s.end_time,g.price,g.name as gname,gi.img,s.gprice'))->table('shopping_group as s,shopping_goods as g,shopping_goodsimg as gi')->where("g.id=s.goods_id  AND g.id=gi.goods_id AND gi.is_main=1")->select();
//        dump($list);die;
        //获得图片的路径
        //图片的路径
        $ms = M('group');
        $res = $ms->select();
        $today = mktime();//即时时间戳
        foreach($res as $k =>$val){
            $end_time = strtotime($res[$k]['end_time']);
            $id = $res[$k]['id'];
            if($end_time<=$today){
                $data['is_lose'] = 0;//0过期
                $res1 = $ms->where("id='$id'")->save($data);
            }else{
                $data['is_lose'] = 1;//1未过期
                $res1 = $ms->where("id='$id'")->save($data);
            }
        }
        $res = $ms->select();
//        $this->assign('today',$today);
//        dump($list);die;
        $this->assign('list',$list);
        $this->display("Group:index");
    }
}